package com.huiketong.cofpasgers.repository;

import com.huiketong.cofpasgers.entity.ShareType;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface ShareTypeRepository extends JpaRepository<ShareType,Integer> {
    @Override
    <S extends ShareType> S save(S s);

    List<ShareType> findShareTypesByCompanyIdOrderBySort(Integer companyId);

    ShareType findShareTypeByCompanyIdAndAndType(Integer companyId,Integer type);

    ShareType findShareTypeById(Integer id);

    @Query(value = "update share_type set title = ?1,img_url = ?2,type = ?3,url = ?4 where id = ?5",nativeQuery = true)
    @Modifying
    @Transactional
    void updateShareType(String title, String imgurl, ShareType shareType, String url, Integer id);
}
